package com.learn.actionplatfo.controller;

import com.learn.actionplatfo.bean.Good;
import com.learn.actionplatfo.bean.Order;
import com.learn.actionplatfo.bean.Price;
import com.learn.actionplatfo.bean.User;
import com.learn.actionplatfo.service.GoodService;
import com.learn.actionplatfo.service.OrderService;
import com.learn.actionplatfo.service.PriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class OrderController {

    @Autowired
    OrderService orderService;

    @Autowired
    GoodService goodService;

    @Autowired
    PriceService priceService;

    @RequestMapping("/creatOrder")
    public String creatOrder(int goodNo,int userNo){
        Good good = goodService.getGoodById(goodNo);
        Price price = priceService.getPriceByGoodId(goodNo);
        Order order = new Order();
        order.setOrderUpPutUser(good.getGoodUpPutUser());
        order.setOrderBuyUser(price.getPriceBuyUserNo());
        order.setOrderGoodNo(goodNo);
        order.setOrderMoney(price.getPriceNow());

        good.setGoodState(2);
        goodService.updateGood(good);
        orderService.addOrder(order);
        return "main";
    }
}
